/*jslint vars: true, forin: true, sloppy: true */
/*global navigator*/
var angular = require('angular');
var probe = require('../global');
require('./upload.html');
probe.controller("upload", function ($scope, $filter, ocDialog, ocDI, ocData,
									Result, project) {
	$scope.result = {
		name: $filter("date")(Date.now(), "yy年M月d日") + ' ' + project.name  + ' 的测试'
	};

	$scope.uploadResult = function () {
		return new Result({
			type: 'case',
			name: $scope.result.name,
			data: angular.toJson({
				ua: navigator.userAgent,
				platform: navigator.platform,
				taskResult: ocData.result
			})
		}).$upload(null, function () {
			ocDI.closeDialog();
		}, function (err) {
			ocDialog.alert({
				title: '上传时出错',
				message: '上传测试结果时出错，原因：\n' + err
			}, ocDI);
		});
	};

	if (ocData.isAutoUpload) $scope.uploadResult();
});
